using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using OVS.BusinessObjects;

namespace OVS.DAL
{
	public partial class VideoDAO
	{
		public VideoDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Video> GetVideos()
		{
			try
			{
				List<Video> lstVideos = new List<Video>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [vide_id],[vide_fn] FROM [Video]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Video oVideo = new Video();
					oVideo.vide_id = Convert.ToInt32(oDbDataReader["vide_id"]);
					oVideo.vide_fn = Convert.ToString(oDbDataReader["vide_fn"]);
					lstVideos.Add(oVideo);
				}
				oDbDataReader.Close();
				return lstVideos;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Video GetVideo(int vide_id)
		{
			try
			{
				Video oVideo = new Video();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [vide_id],[vide_fn] FROM [Video] WHERE [vide_id]=@vide_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@vide_id",DbType.Int32,vide_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oVideo.vide_id = Convert.ToInt32(oDbDataReader["vide_id"]);
					oVideo.vide_fn = Convert.ToString(oDbDataReader["vide_fn"]);
				}
				oDbDataReader.Close();
				return oVideo;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddVideo(Video oVideo)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Video]([vide_fn])VALUES(@vide_fn);SELECT SCOPE_IDENTITY();",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@vide_fn",DbType.String,oVideo.vide_fn));

				return Convert.ToInt32(DbProviderHelper.ExecuteScalar(oDbCommand));
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateVideo(Video oVideo)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Video] SET [vide_fn]=@vide_fn WHERE [vide_id]=@vide_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@vide_fn",DbType.String,oVideo.vide_fn));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@vide_id",DbType.Int32,oVideo.vide_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveVideo(Video oVideo)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Video] WHERE [vide_id]=@vide_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@vide_id",DbType.Int32,oVideo.vide_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveVideo(int vide_id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Video] WHERE [vide_id]=@vide_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@vide_id",DbType.Int32,vide_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
